#include "s_sendexange2.h"
#include "ui_s_sendexange2.h"

#include <QDateTime>
#include <QMessageBox>
#include <QSqlQuery>
extern QString global3;
s_sendExange2::s_sendExange2(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::s_sendExange2)
{
    ui->setupUi(this);
}

s_sendExange2::~s_sendExange2()
{
    delete ui;
}

void s_sendExange2::on_submitBtn_clicked()
{
     QString str=QString("select * from student where sid='%1'").arg(global3);
     QSqlQuery query;
     query.exec(str);
     QString nrid,nbui_bid,rid,bui_bid,because,eresult,eflag,edate,sname;
     QDate date(QDate::currentDate());
     int year=date.year();
     int month=date.month();
     int day=date.day();
     edate=QString("%1.%2.%3").arg(year).arg(month).arg(day);
     qDebug()<<edate;
     if(query.next()){
         nrid=query.value(6).toString();
         nbui_bid=query.value(7).toString();
         rid=ui->needRoomExit->text();
         bui_bid=ui->needBuildExit->text();
         because=ui->whyEdit->toPlainText();
         eresult="null";
         eflag="0";
         sname=query.value(1).toString();
         str=QString("insert into exchangroom "
                     "value('%1',null,'%2','%3','%4','%5','%6',null,'0','%7','%8')")
                     .arg(global3).arg(nrid).arg(nbui_bid).arg(rid).arg(bui_bid).arg(because)
                     .arg(edate).arg(sname);
         qDebug()<<str;
         if(query.exec(str)==true){
             QMessageBox::information(NULL,"tips","申请成功");
             this->close();
         }
         else QMessageBox::warning(NULL,"Error","申请失败,同时只允许进行一个调换申请");
     }
}

